package cn.echo.modules.sys.service;

import cn.echo.modules.sys.dao.AdminDao;
import cn.echo.modules.sys.entity.Admin;
import org.apache.ibatis.session.SqlSession;
import cn.echo.modules.sys.utils.SessionFactory;

import java.util.List;

/**
 * Created by LSF_ on 2017/5/7.
 */
public class AdminService {

 public AdminDao getAdminDao(){
      SqlSession session = SessionFactory.getSession();
     AdminDao adminDao=session.getMapper(AdminDao.class);
     return adminDao;
 }

    //1.查询 admin 所有信息
   public List<Admin> findAll(){
       AdminDao adminDao=this.getAdminDao();
       List<Admin> list=adminDao.findAll();
       return list;

   }
    //1.1根据用户名查id
  public String findIdByUsername(Admin admin){
      AdminDao adminDao=this.getAdminDao();
      return adminDao.findIdByUsername(admin);
  }
//1.2根据用id查所有信息
    public Admin findAdminById(Admin admin){
        AdminDao adminDao=this.getAdminDao();
        return adminDao.findAdminById(admin);
    }
    //1.3 根据Admin id查询出 创建的所有User
    public  Admin findAllUserByAdminId(Admin admin){
        AdminDao adminDao=this.getAdminDao();
        return adminDao.findAllUserByAdminId(admin);
    }
//2.插入一行
    public boolean insertAdmin(Admin admin){
        AdminDao adminDao=this.getAdminDao();
        return adminDao.insertAdmin(admin);
    }
    //3.根据id更新
    public boolean updateAdminById(Admin admin){
        AdminDao adminDao=this.getAdminDao();
        return adminDao.updateAdminById(admin);
    }

    //4.删除数据 根据id name 都可以
    public boolean deleteAdmin(Admin admin){
        AdminDao adminDao=this.getAdminDao();
        return adminDao.deleteAdmin(admin);
    }

}
//    //1.查询 admin 所有信息
//    public List<Admin> findAll();
//    //1.1根据用户名查id
//    public String findIdByUsername(Admin admin);
//    //1.2根据用id查所有信息
//    public Admin findAdminById(Admin admin);
//    //1.3 根据Admin id查询出 创建的所有User
//    public  Admin findAllUserByAdminId(Admin admin);
//
//
//    //2.插入一行
//    public boolean insertAdmin(Admin admin);
//
//    //3.根据id更新
//    public boolean updateAdminById(Admin admin);
//    //4.删除数据 根据id name 都可以
//    public boolean deleteAdmin(Admin admin);